Help Riya find items that exactly match her budget
Help Riya find a combination of grocery items that exactly matches her budget, or determine if no such combination exists.
Prices:
Output: 69
4 6 3
Output: 51
No combination of products
| Price \ Sum | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | T | F | F | F | F | F | F | F | F | F | F | F | F |
| 2 | T | F | T | F | F | F | F | F | F | F | F | F | F |
| 4 | T | F | T | F | T | F | T | F | F | F | F | F | F |
| 6 | T | F | T | F | T | F | T | F | T | F | T | F | T |
Solution: [6, 6] sums to 12
For filling the DP table
For DP and path tables
Example 1: prices = [2, 4, 6, 10, 3], budget = 13 → 69
4 6 3
Example 2: prices = [5, 8, 12, 20], budget = 7 → 51
No combination of products
For filling the DP table
For DP and path tables